﻿@using KRM.Core
@model IEnumerable<KRM.Core.tblTicketDepartment>
@{
    IEnumerable<tblTicket> tickets = ViewBag.Tickets;
}

<table class="table table-ticketdepartment">
    <thead>
        <tr>
            <td style="background: #444; font-size: 23px;">SUPPORT</td>
            @foreach (var item in Model)
            {
                <td style="background: #444; font-size: 23px; padding: 45px 10px">@item.DepartmentName  </td>
            }
        </tr>
    </thead>
    <tbody>
        <tr>
            <td style="font-size: 23px;">New</td>
            @foreach (var item in Model)
            {
                <td style="font-size: 50px">@tickets.Count(a => a.DepartmentId == item.DepartmentID && a.StatusID == 1)  </td>
            }
        </tr>
        <tr>
            <td style="font-size: 23px;">Open</td>
            @foreach (var item in Model)
            {
                <td style="font-size: 50px">@tickets.Count(a => a.DepartmentId == item.DepartmentID && a.StatusID == 2)  </td>
            }
        </tr>
        <tr>
            <td style="font-size: 23px;">Started</td>
            @foreach (var item in Model)
            {
                <td style="font-size: 50px">@tickets.Count(a => a.DepartmentId == item.DepartmentID && a.StatusID == 6)  </td>
            }
        </tr>
        <tr>
            <td style="font-size: 23px;">Pending</td>
            @foreach (var item in Model)
            {
                <td style="font-size: 50px">@tickets.Count(a => a.DepartmentId == item.DepartmentID && a.StatusID == 3)  </td>
            }
        </tr>
        <tr>
            <td style="font-size: 23px;">Oldest</td>
            @foreach (var item in Model)
            {
                var old = tickets.Where(a => a.DepartmentId == item.DepartmentID && a.StatusID == 1).OrderBy(a => a.TicketID).FirstOrDefault();
                if (old != null)
                {
                    TimeSpan tp = DateTime.Now - (DateTime)old.DateAdded;
                    // + tp.Minutes + "m" + tp.Milliseconds + "s   "
                   
                <td style="font-size: 40px">@(tp.Days * 24 + tp.Hours + "h")  </td>
                }
                else
                {
                <td style="font-size: 40px">0h </td>
                }
            }
        </tr>
    </tbody>
</table>